package com.feidu.utils;

import android.content.Context;
import android.content.SharedPreferences;
/**
 * 
 * 生成日期：2016-7-11 <br/>
 * 描述：环信SharedPreference
 */
public class EMSharedPreference {


	/**
	 * 保存Preference的name
	 */
	public static final String PREFERENCE_NAME = "saveInfo";
	private static SharedPreferences mSharedPreferences;
	private static SharedPreferences.Editor editor;

	private static String SHARED_KEY_LOGINSTATE = "shared_key_loginstate";// 登录状态

	private static String SHARED_KEY_CURRENTUSER_USERNAME = "SHARED_KEY_CURRENTUSER_USERNAME";

	private static final String PREF_KEY_EMOID = "emobId";// 环信id

	public static void setCurrentUserName(Context context, String username) {
		mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
		editor = mSharedPreferences.edit();
		editor.putString(SHARED_KEY_CURRENTUSER_USERNAME, username);
		editor.commit();
	}

	public static String getCurrentUsername(Context context) {
		mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
		return mSharedPreferences.getString(SHARED_KEY_CURRENTUSER_USERNAME, null);
	}

	/**
	 * 保存用户环信id
	 * @param context
	 * @param id
	 */
	public static void saveEmoId(Context context, String id) {
		mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
		editor = mSharedPreferences.edit();
		editor.putString(PREF_KEY_EMOID, id);
		editor.commit();
	}

	/**
	 * 获得用户环信id
	 * @param context
	 * @return
	 */
	public static String getEmoId(Context context) {
		mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
		return mSharedPreferences.getString(PREF_KEY_EMOID, null);
	}

	/**
	 * 设置环信登录状态
	 * @param context
	 * @param islogin
	 */
	public static void setIsLoginState(Context context, boolean islogin) {
		mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
		editor = mSharedPreferences.edit();
		editor.putBoolean(SHARED_KEY_LOGINSTATE, islogin);
		editor.commit();
	}

	/**
	 * 获取环信登录状态
	 * @param context
	 * @return
	 */
	public static boolean isLogined(Context context) {
		mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
		return mSharedPreferences.getBoolean(SHARED_KEY_LOGINSTATE, false);
	}

}
